<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>数据角色管理</title>
<script type="text/javascript">
	var $grid;
	var $treeGrid;
	var selectTableRow;//选中的行数据
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			title : '数据角色管理',
			url : "${ctx}/basic/dataRole/dataGrid",
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'dataRoleNo',
				title : '数据角色编号',
				width : 140,
				sortable : true
			}, {
				field : 'dataRoleName',
				title : '数据角色名称',
				width : 140,
				sortable : true
			}, {
				field : 'remark',
				title : '备注',
				width : 200,
				sortable : true
			} ] ],
			onClickRow : function(rowIndex, rowData) {
				selectTableRow = rowData;
				$("#cc").layout("panel", "east").panel({
					title : "数据角色【" + rowData.dataRoleName + "】权限明细"
				});
				fn_refreshDetail();
			}
		}));
		$grid.datagrid('enableFilter');

		$treeGrid = $("#dataDetailTreeGrid").treegrid({
			method : "get",
			url : "${ctx}/basic/dataDetail/treeGrid",
			idField : 'id',
			treeField : 'dataName',
			parentField : "pid",
			remoteSort : true,
			multiSort : true,
			rownumbers : true,
			singleSelect : false,
			fit : true,
			checkOnSelect : false,
			cascadeCheck : true,//级联勾选
			dataPlain : true, //该属性用以启用当前 easyui-treegrid 控件对平滑数据格式的支持
			toolbar : '#codett',
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'dataName',
				title : '数据内容名称',
				width : 160,
				sortable : true
			}, {
				field : 'dataNo',
				title : '数据内容编号',
				width : 100,
				sortable : true
			}, {
				field : 'remark',
				title : '备注',
				width : 160,
				sortable : true
			}, {
				field : 'enableStr',
				title : '是否启用',
				width : 80
			} ] ],
			enableHeaderClickMenu : true, //此属性开启表头列名称右侧那个箭头形状的鼠标左键点击菜单
			enableHeaderContextMenu : true, //此属性开启表头列名称右键点击菜单
			enableRowContextMenu : false
		});

		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load');
			$("#dlg").dialog("open").dialog("setTitle", "新增数据角色");
		});
		$("#detailadd").click(function() {
			fn_rightSave();
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				$.messager.show({
					msg : "您未选中行，无法编辑",
					icon : "warning",
					position : "bottomRight"
				});
			} else {
				$("#dlg").dialog("open").dialog("setTitle", "编辑数据角色");
				$("#fm").form("load", rowData);
			}
		});

		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/basic/dataRole/multiDelete");
		});
		$("#search").click(function() {
			var search_LIKE_dataRoleName = $("#search_LIKE_dataRoleName").val();
			$grid.datagrid('load', {
				search_LIKE_dataRoleName : search_LIKE_dataRoleName
			});
		});
		$("#detailsearch").click(function() {
			var search_LIKE_dataName = $("#search_LIKE_dataName").val();
			$treeGrid.treegrid('load', {
				search_LIKE_dataName : search_LIKE_dataName
			});
			fn_refreshDetail();
		});
	});
	function fn_save() {
		$("#fm").form("submit", {
			url : "${ctx}/basic/dataRole/update",
			success : function(data) {
				$grid.datagrid("load");
				$.messager.show({
					msg : "保存成功",
					icon : "info",
					position : "bottomRight"
				});
				$("#dlg").dialog('close');
			}
		});
	}
	function fn_rightSave() {
		var checkedData = $treeGrid.treegrid("getChecked");
		if (selectTableRow == null) {
			$.messager.show({
				msg : "请先选定数据角色",
				icon : "warning",
				position : "bottomRight"
			});
			return false;
		}
		var dataDetailIds = "";
		for (var i = 0; i < checkedData.length; i++) {
			if (checkedData[i].pid) {//如果为子节点
				dataDetailIds += (checkedData[i].id + ",");
			}
		}
		$.post("${ctx}/basic/dataRole/addDataDetails", {
			dataRoleId : selectTableRow.id,
			dataDetailIds : dataDetailIds
		}, function(result) {
			$.messager.show({
				msg : result.msg,
				icon : "info",
				position : "bottomRight"
			});
			if (result.success) {
				fn_refreshDetail();
			}
		}, 'json');
	}

	function fn_refreshDetail() {
		if (!selectTableRow) {
			$.messager.show({
				msg : "请先选定数据角色",
				icon : "warning",
				position : "bottomRight"
			});
			return false;
		}
		$.get("${ctx}/basic/dataRole/jsonDataDetailsOfDataRole?dataRoleId=" + selectTableRow.id, function(result) {
			if (result.success && result.obj) {
				$treeGrid.treegrid("clearChecked");
				for (var i = 0; i < result.obj.length; i++) {
					var node = $treeGrid.treegrid("find", result.obj[i]);
					if (node) {
						$treeGrid.treegrid("check", node);
					}
				}
			} else {
				$.messager.show({
					msg : result.msg,
					icon : "info",
					position : "bottomRight"
				});
			}
		}, 'json');
	}
</script>
</head>

<body class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center'" data-options="fit:true" style="padding: 1px;">
		<div id="cc" class="easyui-layout" data-options="fit:true" style="width: 480px; height: 440px;">
			<div data-options="region:'center'" style="padding: 1px; witdh: 500px;height:60%">
				<table id="grid">
				</table>
			</div>
			<div id="tt" class="row">
			<!-- <div class="col-md-4">
				<shiro:hasPermission name="dataRole:list">
				<form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="search_LIKE_dataRoleName" placeholder="数据角色名称" />
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
				</shiro:hasPermission>
				</div> -->
				<div class="col-md-12">
				<shiro:hasPermission name="dataRole:update">
					<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
				</shiro:hasPermission>
				<shiro:hasPermission name="dataRole:delete">
					<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
				</shiro:hasPermission>
				</div>
			</div>
			<shiro:hasPermission name="dataRole:update">
				<div id="dlg" class="easyui-dialog" style="width: 370px; height: 275px; padding: 10px 20px"
					data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
					<form id="fm" method="post">
						<input type="hidden" name="id" />
						<table id="tbl">
							<tr>
								<td><label>数据角色编号:</label></td>
								<td><input name="dataRoleNo" class="easyui-validatebox" data-options="required:true" /></td>
							</tr>
							<tr>
								<td><label>数据角色名称:</label></td>
								<td><input name="dataRoleName" class="easyui-validatebox" data-options="required:true" /></td>
							</tr>
							<tr>
								<td><label>备注:</label></td>
								<td><input name="remark" class="easyui-textbox" data-options="multiline:true,width:185,height:60"></td>
							</tr>
						</table>

					</form>
					<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="fn_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
				</div>
			</shiro:hasPermission>
			<div data-options="region:'east', title:'数据内容', split: true, collapsible:true" style="padding: 1px; witdh: 600px;height:40%">
				<shiro:hasPermission name="dataRole:list">
					<table id="dataDetailTreeGrid">
					</table>
				</shiro:hasPermission>
				<div id="codett" class="row">
				<div class="col-md-8">
					<shiro:hasPermission name="dataRole:list">
					<form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="search_LIKE_dataName" placeholder="内容名称" />
				</div>
				<button type="button" id="detailsearch" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
					</shiro:hasPermission></div>
					<div class="col-md-4">
					<shiro:hasPermission name="dataRole:update">
					<button id="detailadd" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 保存配置
				</button>
					</shiro:hasPermission></div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
